package com.cvte.boe.media.utils;

import android.content.Context;

import com.cvte.boe.media.utils.constant.Constant;

import java.io.File;


/**
 * Created by liyang on 2015/06/13.
 *
 * @功能 tv_media_config.xml功能配置类
 */
public class MediaDataUtil {
    private final static String[] SUPPORT_IMAGE_FORMAT = {
            ".bmp", ".jpg", ".gif", ".png", ".jpeg", ".jpe", ".pcd", ".qti",
            ".qtf", ".ico", ".pnm", ".ppm"};
    private final static String[] SUPPORT_AUDIO_FORMAT = {
            ".mp3", ".flac", ".ape", ".aac", ".ac3", ".wav", ".wmv", ".wma",
            ".amr", ".aac"};
    private final static String[] SUPPORT_VIDEO_FORMAT = {
            ".mp4", ".mov", ".mpg", ".dat", ".vob", ".mpeg", ".ts", ".trp",
            "tp", "avi", ".3gp", ".3gpp", ".mkv", ".divx", ".flv", ".asf", ".swf", ".vod",
            ".wmv", ".asf", ".rm", "rmvb"};
    private final static String[] SUPPORT_SUBTITLE_FORMAT = {
            ".ass", ".lrc", ".srt", ".smi", ".sub", ".pgs", ".dvb", ".dvd", ".ssa", ".txt"
    };


    public static String[] getImageSupport() {
        return SUPPORT_IMAGE_FORMAT;
    }

    public static String[] getAudioSupport() {
        return SUPPORT_AUDIO_FORMAT;
    }

    public static String[] getVideoSupport() {
        return SUPPORT_VIDEO_FORMAT;
    }

    public static String[] getSubtitleSupport() {
        return SUPPORT_SUBTITLE_FORMAT;
    }

    public static int getMediaType(File file) {
        if(file.isDirectory()){
            return Constant.MediaType.FOLDER;
        }
        String path = file.getAbsolutePath();
        if(isSupportMediaType(Constant.MediaType.IMAGE,path)){
            return Constant.MediaType.IMAGE;
        }
        if(isSupportMediaType(Constant.MediaType.AUDIO,path)){
            return Constant.MediaType.AUDIO;
        }
        if(isSupportMediaType(Constant.MediaType.VIDEO,path)){
            return Constant.MediaType.VIDEO;
        }
        return Constant.MediaType.UNKNOWN_TYPE;
    }

    public static boolean isSupportMediaType(int type, String filePath) {
        if (filePath == null) {
            return false;
        }
        String[] supportFormat;
        switch (type) {
            case Constant.MediaType.IMAGE:
                supportFormat = SUPPORT_IMAGE_FORMAT;
                break;
            case Constant.MediaType.AUDIO:
                supportFormat = SUPPORT_AUDIO_FORMAT;
                break;
            case Constant.MediaType.VIDEO:
                supportFormat = SUPPORT_VIDEO_FORMAT;
                break;
            default:
                supportFormat = null;
                return false;
        }
        for (String suffix : supportFormat) {
            if (filePath.toLowerCase().endsWith(suffix)) {
                return true;
            }
        }
        return false;
    }

}
